package de.mafr.jsystest.matchers;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import de.mafr.jsystest.ws.Response;


/**
 * Checks if a response was successful (status code 2xx).
 * 
 * We use <?> or otherwise the type system would require
 * a cast inside of assertThat().
 */
public class IsOk extends TypeSafeMatcher<Response<?>> {
	
	@Override
	public boolean matchesSafely(Response<?> actual) {
		if (actual.getStatusCode() >= 200 && actual.getStatusCode() < 300)
			return true;
		else
			return false;
	}

	public void describeTo(Description description) {
		description.appendText("ok");
	}

	@Factory
	public static Matcher<Response<?>> ok() {
		return new IsOk();
	}
}
